import json


f = open('合成.json', encoding='utf-8')
content = f.read()
data = json.loads(content)

def getBuildingsRecipe(data):
    matters = {}
    for build in data['building']:
        # print(build['from'][0])
        for matter in build['from'][0]['matter'].keys():
            matters[matter] = 0

    print(matters.keys())
    print(len(matters))

elements = data['assembly'] + data['building']

def getBeltConsumeAll(elements):
    for element in elements:
        if 'from' not in element:
            continue

        print(element['name'] + ':')
        for recipe in element['from']:
            matters = {}
            matters.update(recipe['matter'])
            matters.update(recipe['product'])
            time = recipe['cost']
            print('\t材料:')
            for matter in recipe['matter']:
                print('\t\t'+matter + ':' + str(30*time/ matters[matter]), end='\t')
            print()
            print('\t产物:')
            for matter in recipe['product']:
                print('\t\t'+matter+':'+str(30*time/matters[matter]), end='\t')
            print()


getBeltConsumeAll(elements)
            
